<style type="text/css">
    @media only screen and (min-width: 450px) {
        .a {
            width: 310px;
            position: absolute;
            left: calc(100% / 2 - 170px);
            margin-top: 150px;
            /*box-shadow: 0px 0px 20px #888888;;*/
            padding: 10px;
            /*padding-top: 5px;*/
            border-radius:1px;
            /*background: rgba(0,0,0,0.3);*/
            
        }
        body {
            /*background: #ddd;*/
            background: #eee;
        }
    }
    .a .other{
            margin-top: 10px;
            display: inline-block;
        }
    .a h2{
            margin-top: 5px;
            margin-bottom: 20px;
            text-align: center;
            color: gray;
        }
    .verification{
        width: 100%;
        margin-bottom: 10px;
    }
    .verification .ver-img img{
        cursor: pointer;
        height: 38px;
        width: 100px;
        border: 1px solid #e6e6e6;
    }
    .verification .ver-input{
        float: right;
        margin: 0;
    }
    .enian-float-right{
        float: right;
    }
    body a{
        cursor: pointer;    
    }
    .qr-login{
        /*height: 300px;
        width: 400px;*/
        /*background: gray;*/
    }
    .qr-login img{
        margin-top: 10px;
        height: 170px;
        
    }
    .qr-login .content{
        margin: auto;
        text-align: center;
    }
    .qr-login .content .text{
        margin-top: 20px;
    }
    .qr-login .content .wxapp-qr{
        color: blueviolet;
    }
    #wxapp-logo{
        position: absolute;
        top: 30px;
        /*border: 1px solid darkgray;*/
        
        left: calc(100% - 50% - 170px / 2);
    }
    #wxapp-logo img{
        border: 1px solid #e6e6e6;
        height: 150px;
    }
    @media only screen and (max-width: 449px) {
        .a {
            width: 90%;
            margin: 60px auto;
        }
    }
</style>
<div class='layui-main a'>
    <h2  class="title">日历记事本 - 重置密码</h2>

    <form class="layui-form layui-form-pane" action="" method="POST" lay-filter="forgetPasswordFormUsername">
    
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="username" required lay-verify="required" placeholder="请输入注册邮箱" class="layui-input">
            </div>
        </div>
    
        <div class="layui-form-item" align="center">
            <a class="layui-btn layui-btn-fluid layui-btn-normal layui-btn-sm" lay-submit="" id='btn_get_v_code' lay-filter="btn_get_v_code">获取验证码</a>
        </div>
    </form>

    <form class="layui-form layui-form-pane" action="" method="POST" lay-filter="forgetPasswordSetPassword">

        <div class="layui-form-item">
            <label class="layui-form-label">验证码</label>
            <div class="layui-input-block">
                <input type="text" name="v_code" required lay-verify="required" placeholder="请输入验证码" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入新密码" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" name="password_again" required lay-verify="required" placeholder="请再次输入新密码" class="layui-input">
            </div>
        </div>

        
        
        <div class="layui-form-item" align="center">
            <a class="layui-btn layui-btn-fluid layui-btn-normal" lay-submit="" id='btn_regster'>修改密码</a>
        </div>
<!--         <a href="">注册账号</a>
        <a class="enian-float-right" href="">忘记密码?</a> -->
        
    </form>
</div>

        

<script>
    app.base.loadApi('apiLogin');
    layui.use(['form', 'layer','jquery','laytpl','apiLogin'], function() {
        var form = layui.form;
        var $ = layui.jquery;
        var laytpl = layui.laytpl;
        var timeOut
        var qrContent={
                type:'login'
                ,code:false
            };
        var sendVCodeSceond=59;
        var vCodeIntervalId=0;

        app.base.setTitle('日历记事本 - 重置密码');
        var username='';

        $('#btn_regster').click(function () {
            var data = form.val('forgetPasswordSetPassword');
            if (data.password !== data.password_again) {
                layer.msg('两次密码输入不一致');
                return;
            }
            var loading_layer = layer.msg('加载中', {
                icon: 16
                , shade: 0.01
                , time: 0
            });

            // 重置密码接口请求 需要关闭弹窗 layer.close(loading_layer);
            layui.apiLogin.resetPassword(username,data.v_code,data.password, function () {
                layer.close(loading_layer);
                layer.msg('重置成功。马上登录吧');
                app.go(app.base.route.login);
            }, function (msg) {
                layer.close(loading_layer);
                layer.msg(msg)
            })
        })
        
        // 发送验证码
        form.on('submit(btn_get_v_code)', function (data) {
            if (sendVCodeSceond != 59) {
                layer.msg('请不要频繁点击');
                return;
            }

            var data = form.val('forgetPasswordFormUsername');
            // 发送验证码请求
            layui.apiLogin.getResetPasswordVCode(data.username, function () {
                username = data.username;
                layer.msg('验证码已发送，请不要重复点击');
                vCodeIntervalId = setInterval(function () {
                    if (sendVCodeSceond <= 0) {
                        clearInterval(vCodeIntervalId);
                        $('#btn_get_v_code').text('获取验证码')
                        sendVCodeSceond = 59;
                    } else {
                        $('#btn_get_v_code').text('获取验证码 (' + sendVCodeSceond + "秒)")
                        sendVCodeSceond--
                    }
                }, 1000);
            }, function (msg) {
                layer.msg(msg)
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        // 页面关闭销毁定时器
        app.eventRegister('pageClose', function(){
            clearInterval(vCodeIntervalId);
        })
        
     
    });
</script>
